/** 
  Copyright (c) 2008, 2009 Claudio Imbrenda
  This program is released under the terms of the
  GNU GPL version 3 or later.
*/
package interfaccia;

import java.awt.event.*;
import java.awt.Color;
import java.awt.Dimension;
import java.util.*;
import javax.swing.*;

import static macchina.MRUtils.*;
import static interfaccia.MRMainFrame.resizeIcon;

/**
 *
 * @author  Claudio Imbrenda
 */
public class MRTapeElementPanel extends javax.swing.JPanel { 
    
    /** Creates new form MRTapeElementPanel */
    public MRTapeElementPanel() {
        this(false,(byte)0);
    }
    
    private static ImageIcon image_i =
                resizeIcon(new ImageIcon(MRTapeElementPanel.class
                .getResource("/interfaccia/pallino-pieno-grigio.png")), 8, 8);
    private static ImageIcon image_si =
                resizeIcon(new ImageIcon(MRTapeElementPanel.class
                .getResource("/interfaccia/pallino-vuoto-grigio.png")), 8, 8);
    private static ImageIcon image_di =
                resizeIcon(new ImageIcon(MRTapeElementPanel.class
                .getResource("/interfaccia/pallino-pieno.png")), 8, 8);
    private static ImageIcon image_dsi =
                resizeIcon(new ImageIcon(MRTapeElementPanel.class
                .getResource("/interfaccia/pallino-vuoto.png")), 8, 8);
    
    private static ImageIcon image_dot_big = 
                resizeIcon(new ImageIcon(MRTapeElementPanel.class
                .getResource("/interfaccia/pallino-vuoto.png")),10,10);
    private static ImageIcon image_dot_small =
                resizeIcon(new ImageIcon(MRTapeElementPanel.class
                .getResource("/interfaccia/pallino-vuoto.png")), 4, 4);

    /** Creates new form MRTapeElementPanel
     * @param newid the id assigned to this instance.
     * @param addertype if true, behaves correctly for the element adder
     * instance.
     */
    public MRTapeElementPanel(boolean ishist, byte value) {
        initComponents();
        radios[0]= jCheckBox1;
        radios[1]= jCheckBox2;
        radios[2]= jCheckBox3;
        radios[3]= jCheckBox4;
        radios[4]= jCheckBox5;
        
        if(!ishist)jLabel1.setIcon(image_dot_big);
        setValue(value);
        setEditable(false);
        jButton3.setVisible(false);
        ishistorical=ishist;

        
        

        if(ishist){
            jSeparator1.setVisible(false);jSeparator2.setVisible(false);
            jSeparator3.setVisible(false);jSeparator4.setVisible(false);
            jSeparator5.setVisible(false);jSeparator6.setVisible(false);
            jSeparator7.setVisible(false);

            jTextField1.setVisible(false);jTextField2.setVisible(false);
            jTextField3.setVisible(false);jTextField4.setVisible(false);
            
            
            jLabel1.setIcon(image_dot_small);
            jLabel1.setPreferredSize(new Dimension(4, 10));
            jLabel1.setMaximumSize(new Dimension(4, 10));
            jLabel1.setMinimumSize(new Dimension(4, 10));
            
            for(int cx=0;cx<5;cx++){
                radios[cx].setIcon(image_i);
                radios[cx].setSelectedIcon(image_si);
                radios[cx].setDisabledIcon(image_di);
                radios[cx].setDisabledSelectedIcon(image_dsi);
                radios[cx].setPreferredSize(new Dimension(10, 10));
                radios[cx].setMaximumSize(new Dimension(10, 10));
                radios[cx].setMinimumSize(new Dimension(10, 10));
                
            }
            jToolBar1.validate();
        }
    }    
    
    private List<ActionListener> acl = new ArrayList<ActionListener>();
    
    private byte value=0;
    
    private JCheckBox[] radios = new JCheckBox[5];
    boolean isedit = true;
    boolean isaddable = true;

    private boolean ismousein=false;
    private boolean isselected=false;

    public static final Color giallino = new Color(255,255,127);
    public static final Color giallone = Color.YELLOW;
    private boolean ishistorical=false;

    
    public byte getValue(){
        return value;
    }
    
    
    public void setValue(byte v){
        value=(byte)(v&0x1f);
        updatedisplay(false);
    }

    public boolean isEditable(){return isedit;}

    public void setEditable(boolean b){
        if(ishistorical)return;
        isedit=isaddable=b;
        for(JCheckBox c : radios)c.setEnabled(b);
        jTextField4.setEditable(b);
        jButton2.setEnabled(b);
        jButton1.setEnabled(b);
        if(!b){
            jButton1.setVisible(b);
            jButton2.setVisible(b);
            jTextField4.setVisible(b);
        }
        validate();
    }

    public void setAddable(boolean b){
        if(ishistorical)return;
        isaddable=b;
        jButton2.setEnabled(b);
        if(!b)jButton2.setVisible(b);
    }

    private void updatedisplay(boolean checks){
        if(!checks)
            for(int cx=0;cx<5;cx++)
                radios[4-cx].setSelected((value&(1<<cx))!=0);
        jTextField1.setText(""+value);
        jTextField2.setText(""+toASCII(value,false));
        jTextField3.setText(""+toASCII(value,true));
        jTextField4.setText(""+value);
    }
    
    private void fireaction(final String action){
        for(ActionListener al:acl)
            al.actionPerformed(new ActionEvent(this, 0, action));
    }
    
    
    public void addActionListener(ActionListener a){
        acl.add(a); 
    }
    
    public boolean removeActionListener(ActionListener a){
        return acl.remove(a);
    }

    public void setSelected(boolean v){
        isselected=v;
        if(v)jToolBar1.setBackground(Color.WHITE);
        else jToolBar1.setBackground(giallino);
    }
    

    public void do_mouseEntered(){
        if(ishistorical)return;
        jTextField4.setVisible(isedit);
        jButton1.setVisible(isedit);
        jToolBar1.setBackground(isedit?giallone:giallino);

        jButton2.setVisible(isaddable);
        jButton3.setVisible(true);
        ismousein=true;
    }

    public void do_mouseExited(){
        if((!ismousein)||ishistorical)return;
        jTextField4.setVisible(false);
        jButton1.setVisible(false);
        jButton2.setVisible(false);
        jButton3.setVisible(false);
        jToolBar1.setBackground(isselected?Color.WHITE:giallino);
        ismousein=false;
        validate();

    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jToolBar1 = new javax.swing.JToolBar();
    jCheckBox1 = new javax.swing.JCheckBox();
    jCheckBox2 = new javax.swing.JCheckBox();
    jCheckBox3 = new javax.swing.JCheckBox();
    jLabel1 = new javax.swing.JLabel();
    jCheckBox4 = new javax.swing.JCheckBox();
    jCheckBox5 = new javax.swing.JCheckBox();
    jSeparator7 = new javax.swing.JToolBar.Separator();
    jTextField1 = new javax.swing.JTextField();
    jSeparator1 = new javax.swing.JToolBar.Separator();
    jTextField2 = new javax.swing.JTextField();
    jSeparator2 = new javax.swing.JToolBar.Separator();
    jTextField3 = new javax.swing.JTextField();
    jSeparator3 = new javax.swing.JToolBar.Separator();
    jTextField4 = new javax.swing.JTextField();
    jSeparator4 = new javax.swing.JToolBar.Separator();
    jButton1 = new javax.swing.JButton();
    jSeparator5 = new javax.swing.JToolBar.Separator();
    jButton2 = new javax.swing.JButton();
    jSeparator6 = new javax.swing.JToolBar.Separator();
    jButton3 = new javax.swing.JButton();

    setMaximumSize(new java.awt.Dimension(512, 22));
    setLayout(new java.awt.BorderLayout());

    jToolBar1.setBackground(new java.awt.Color(255, 255, 127));
    jToolBar1.setBorder(null);
    jToolBar1.setFloatable(false);
    jToolBar1.setRollover(true);
    jToolBar1.setMaximumSize(new java.awt.Dimension(0, 22));
    jToolBar1.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });

    jCheckBox1.setContentAreaFilled(false);
    jCheckBox1.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-pieno.png"))); // NOI18N
    jCheckBox1.setDisabledSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto.png"))); // NOI18N
    jCheckBox1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jCheckBox1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-pieno-grigio.png"))); // NOI18N
    jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jCheckBox1.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto-grigio.png"))); // NOI18N
    jCheckBox1.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jCheckBox1actionPerformed(evt);
      }
    });
    jToolBar1.add(jCheckBox1);

    jCheckBox2.setContentAreaFilled(false);
    jCheckBox2.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-pieno.png"))); // NOI18N
    jCheckBox2.setDisabledSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto.png"))); // NOI18N
    jCheckBox2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jCheckBox2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-pieno-grigio.png"))); // NOI18N
    jCheckBox2.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jCheckBox2.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto-grigio.png"))); // NOI18N
    jCheckBox2.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jCheckBox1actionPerformed(evt);
      }
    });
    jToolBar1.add(jCheckBox2);

    jCheckBox3.setContentAreaFilled(false);
    jCheckBox3.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-pieno.png"))); // NOI18N
    jCheckBox3.setDisabledSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto.png"))); // NOI18N
    jCheckBox3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jCheckBox3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-pieno-grigio.png"))); // NOI18N
    jCheckBox3.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jCheckBox3.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto-grigio.png"))); // NOI18N
    jCheckBox3.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jCheckBox1actionPerformed(evt);
      }
    });
    jToolBar1.add(jCheckBox3);

    jLabel1.setFont(new java.awt.Font("Dialog", 1, 18));
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto-grigio.png"))); // NOI18N
    jLabel1.setMaximumSize(new java.awt.Dimension(10, 22));
    jLabel1.setMinimumSize(new java.awt.Dimension(10, 22));
    jLabel1.setPreferredSize(new java.awt.Dimension(10, 22));
    jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jLabel1);

    jCheckBox4.setContentAreaFilled(false);
    jCheckBox4.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-pieno.png"))); // NOI18N
    jCheckBox4.setDisabledSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto.png"))); // NOI18N
    jCheckBox4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jCheckBox4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-pieno-grigio.png"))); // NOI18N
    jCheckBox4.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jCheckBox4.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto-grigio.png"))); // NOI18N
    jCheckBox4.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jCheckBox4.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jCheckBox1actionPerformed(evt);
      }
    });
    jToolBar1.add(jCheckBox4);

    jCheckBox5.setContentAreaFilled(false);
    jCheckBox5.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-pieno.png"))); // NOI18N
    jCheckBox5.setDisabledSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto.png"))); // NOI18N
    jCheckBox5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jCheckBox5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-pieno-grigio.png"))); // NOI18N
    jCheckBox5.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jCheckBox5.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/pallino-vuoto-grigio.png"))); // NOI18N
    jCheckBox5.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jCheckBox5.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jCheckBox1actionPerformed(evt);
      }
    });
    jToolBar1.add(jCheckBox5);

    jSeparator7.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jSeparator7);

    jTextField1.setEditable(false);
    jTextField1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
    jTextField1.setText("###");
    jTextField1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
    jTextField1.setEnabled(false);
    jTextField1.setMaximumSize(new java.awt.Dimension(34, 18));
    jTextField1.setMinimumSize(new java.awt.Dimension(34, 18));
    jTextField1.setOpaque(false);
    jTextField1.setPreferredSize(new java.awt.Dimension(34, 18));
    jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jTextField1);

    jSeparator1.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jSeparator1);

    jTextField2.setEditable(false);
    jTextField2.setText("#");
    jTextField2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
    jTextField2.setEnabled(false);
    jTextField2.setMaximumSize(new java.awt.Dimension(12, 18));
    jTextField2.setMinimumSize(new java.awt.Dimension(12, 18));
    jTextField2.setOpaque(false);
    jTextField2.setPreferredSize(new java.awt.Dimension(12, 18));
    jTextField2.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jTextField2);

    jSeparator2.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jSeparator2);

    jTextField3.setEditable(false);
    jTextField3.setText("#");
    jTextField3.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
    jTextField3.setEnabled(false);
    jTextField3.setMaximumSize(new java.awt.Dimension(12, 18));
    jTextField3.setMinimumSize(new java.awt.Dimension(12, 18));
    jTextField3.setOpaque(false);
    jTextField3.setPreferredSize(new java.awt.Dimension(12, 18));
    jTextField3.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jTextField3);

    jSeparator3.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jSeparator3);

    jTextField4.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    jTextField4.setText("0");
    jTextField4.setMaximumSize(new java.awt.Dimension(48, 20));
    jTextField4.setMinimumSize(new java.awt.Dimension(48, 20));
    jTextField4.setPreferredSize(new java.awt.Dimension(48, 20));
    jTextField4.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jTextField4.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField4ActionPerformed(evt);
      }
    });
    jTextField4.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusLost(java.awt.event.FocusEvent evt) {
        jTextField4FocusLost(evt);
      }
    });
    jToolBar1.add(jTextField4);

    jSeparator4.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jSeparator4);

    jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/cross.png"))); // NOI18N
    java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("interfaccia/Bundle_interfaccia"); // NOI18N
    jButton1.setToolTipText(bundle.getString("Rimuovi_questo_elemento")); // NOI18N
    jButton1.setFocusable(false);
    jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    jToolBar1.add(jButton1);

    jSeparator5.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jSeparator5);

    jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/add.png"))); // NOI18N
    jButton2.setToolTipText(bundle.getString("Aggiungi")); // NOI18N
    jButton2.setFocusable(false);
    jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    jToolBar1.add(jButton2);

    jSeparator6.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jToolBar1.add(jSeparator6);

    jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/arrow_left.png"))); // NOI18N
    jButton3.setToolTipText(bundle.getString("Imposta_come_posizione_corrente")); // NOI18N
    jButton3.setFocusable(false);
    jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton3.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jToolBar1MouseExited(evt);
      }
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jToolBar1MouseEntered(evt);
      }
    });
    jButton3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton3ActionPerformed(evt);
      }
    });
    jToolBar1.add(jButton3);

    add(jToolBar1, java.awt.BorderLayout.NORTH);
  }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(jButton1.isEnabled())fireaction("del");
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        try{
            byte b = (byte)(Byte.parseByte(jTextField4.getText())&0x1f);
            if(b==value)return;
            value =b;
            updatedisplay(false);
            fireaction("edit");
        }catch(NumberFormatException ignore){}
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void jTextField4FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField4FocusLost
        jTextField4ActionPerformed(null);
    }//GEN-LAST:event_jTextField4FocusLost

    private void jCheckBox1actionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1actionPerformed
        value= (byte)((radios[0].isSelected()?16:0) + (radios[1].isSelected()?8:0) +
                (radios[2].isSelected()?4:0)+(radios[3].isSelected()?2:0)+
                (radios[4].isSelected()?1:0));
        updatedisplay(true);
        fireaction("edit");
}//GEN-LAST:event_jCheckBox1actionPerformed

    private void jToolBar1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToolBar1MouseEntered
        do_mouseEntered();
        fireaction("entered");
    }//GEN-LAST:event_jToolBar1MouseEntered

    private void jToolBar1MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToolBar1MouseExited
        do_mouseExited();
    }//GEN-LAST:event_jToolBar1MouseExited

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        if(jButton2.isEnabled())fireaction("add");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        if(jButton3.isEnabled())fireaction("curr");
    }//GEN-LAST:event_jButton3ActionPerformed
    
    
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JButton jButton3;
  private javax.swing.JCheckBox jCheckBox1;
  private javax.swing.JCheckBox jCheckBox2;
  private javax.swing.JCheckBox jCheckBox3;
  private javax.swing.JCheckBox jCheckBox4;
  private javax.swing.JCheckBox jCheckBox5;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JToolBar.Separator jSeparator1;
  private javax.swing.JToolBar.Separator jSeparator2;
  private javax.swing.JToolBar.Separator jSeparator3;
  private javax.swing.JToolBar.Separator jSeparator4;
  private javax.swing.JToolBar.Separator jSeparator5;
  private javax.swing.JToolBar.Separator jSeparator6;
  private javax.swing.JToolBar.Separator jSeparator7;
  private javax.swing.JTextField jTextField1;
  private javax.swing.JTextField jTextField2;
  private javax.swing.JTextField jTextField3;
  private javax.swing.JTextField jTextField4;
  private javax.swing.JToolBar jToolBar1;
  // End of variables declaration//GEN-END:variables
    
}
